import argparse
import time
import sys
import random

if __name__ == "__main__":
    format = "%Y%m%d %H:%M:%S"
    parser = argparse.ArgumentParser(
        description='auto generate influxdb data'
    )
    parser.add_argument('-s', type=str, help='start day', default='')
    parser.add_argument('-e', type=str, help='end day', default='')
    parser.add_argument('-i', type=int, help='frequency(seconds)', default=60)
    
    args = parser.parse_args()
    start_ts = (int)(time.mktime(time.strptime(args.s, "%Y%m%d %H:%M:%S")))
    end_ts = (int)(time.time())
    interval = args.i
    if args.s == '':
        sys.stderr.write('' + '\n')
    if args.e != '':
        end_ts = (int)(time.mktime(time.strptime(args.e, "%Y%m%d %H:%M:%S")))
    if args.i == '':
        sys.stderr.write('' + '\n')

    measurement = 'food'
    #tags = ['name': '', 'origin_place', 'tempature']
    base_ns = '000000000'    
    while start_ts < end_ts:
        #print("%s,%s=%s,%s=%s %s=%s" % (measure))
        print('food,name=fish,place=sy temp=%s %s' % (random.randint(1,100), str(start_ts) + base_ns))
        start_ts += interval